package com.yizhilu.os.edu.servlet;

import java.util.Scanner;

import com.yizhilu.os.common.util.AccessToken;
import com.yizhilu.os.common.util.WeChatUtil;

public class CreateMenu {

	/**
	 *
	 */
	@SuppressWarnings("resource")
	public static void createMenu() {		
		
		String url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3d1f8a4e695dfd27&redirect_uri=http://www.kuaijidao.cn/mobile/bind&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
		
		String zuourl ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx3d1f8a4e695dfd27&redirect_uri=http://www.kuaijidao.cn/mobile/zuoti&response_type=code&scope=snsapi_base&state=0#wechat_redirect";
		
		
		String menujson  = "{\"button\":[{\"type\":\"view\",\"name\":\"开始学习\",\"url\":\""+url+" \"},{\"type\":\"view\",\"name\":\"做题\",\"url\":\""+zuourl+" \"}}";;  
		
		//获取Token （获取到的Token2小时有效，可重复使用）
		AccessToken at = WeChatUtil.getAccessToken(); 
		
		if (at!=null&&at.getToken()!=null) {
			
			System.out.println("获取到的TOKEN：\n"+at.getToken());
			// 调用接口创建菜单
			int result = WeChatUtil.createMenu(menujson,at.getToken());
			// 判断菜单创建结果
			if (0 == result)
				System.out.println("菜单创建成功");
			else
				System.out.println("菜单创建失败");
		}else
			System.out.println("菜单创建失败");
	}

}
